<?php
// set number of products that are displayed on each screen
// PRODUCT_LIST_LIMIT is set in local Configuration file
$intLimit = PRODUCT_LIST_LIMIT;
    $strSQL = "SELECT 
				 tblProduct.ID ProductID
				,tblProduct.Product 				\"ProductName\"
				,tblProduct.Description
				,tblProduct.Supplier 				\"SupplierID\"
				,tblProduct.Category  				\"CategoryID\"
				,tblProduct.SupplierProductID
				,tblProduct.QuantityPerUnit 
				,tblProduct.OwnProductCode 
				,tblProduct.UnitPrice 
				,tblProduct.FullPrice 
				,tblProduct.UnitsInStock 
				,tblProduct.UnitsOnOrder 
				,tblProduct.ReorderLevel 
				,tblProduct.Discontinued  
				,tblProduct.PromotionalItem 
				,tblProduct.UploadedPicture 		\"Picture\"
				,tblCategory.Category				\"CategoryName\"
				,tblCategory.Description 			\"Desc\"
				,tblCategory.Description 			\"CategoryDescription\"
				,tblCategory.UploadedPicture		\"UploadedPicture\"
				FROM tblProduct
				LEFT JOIN tblCategory ON tblProduct.Category = tblCategory.ID";
	$strJoin = " WHERE ";
	$strSQL .= $strJoin."tblProduct.Discontinued =  '0' ";
	
	$strJoin = " AND ";
	
    if (isset($nCategoryID))
    {
    	$strSQL .= $strJoin."tblProduct.Category =  '".mysql_real_escape_string($nCategoryID)."' ";
		$strJoin = " AND ";
    }elseif (isset($_GET['strCategoryList']))
    {
    	$strSQL .= $strJoin."tblProduct.Category IN (".$_GET['strCategoryList'].")";
		$strJoin = " AND ";
    }
    
    if(isset($boPromotional))
    {
            $strSQL .= $strJoin."tblProduct.PromotionalItem =  '1' ";
			$strJoin = " AND ";
    }
		
/*
	if(!$strProductListOrder){
		$strSQL .= " ORDER BY ProductName";
	}else{
  		$strSQL .= " ORDER BY ".$strProductListOrder; //
	} 
*/
	if(!PRODUCT_LIST_ORDER){
		$strSQL .= " ORDER BY ProductName";
	}else{
  		$strSQL .= " ORDER BY ".PRODUCT_LIST_ORDER; //
	} 
	
	if (isset($strDirection)){
		
	
		switch ($strDirection){;
			case "Next";
				$_SESSION['sesFirstLine'] = $_SESSION['sesFirstLine'] + $intLimit;
				break;
				
			Case "Prev";
				if ($_SESSION['sesFirstLine'] - $intLimit >= 0){
					$_SESSION['sesFirstLine'] = $_SESSION['sesFirstLine'] - $intLimit;}
				break;
			Case "First";
				$_SESSION['sesFirstLine'] = "0";
				break;
			case "Current";
				if(!$_SESSION['sesFirstLine']){
					$_SESSION['sesFirstLine'] = 0;
				}
				break;	
				
			case "SelectPage":
				$_SESSION['sesFirstLine'] = ($intSelectedPage * PRODUCT_LIST_LIMIT) - PRODUCT_LIST_LIMIT;
				break;
		}
				
		$_SESSION['sesLastLine']  = $intLimit;
		//session_register(sesLastLine);
		$_SESSION['sesFirstLine'] = $_SESSION['sesFirstLine'];


		$strSQL .= " LIMIT ".$_SESSION['sesFirstLine'].", ".$_SESSION['sesLastLine'];
	}
	//echo $strSQL;
    include (MODULE . "/action/actMySqlResults");
	
	//$nCategoryID="";
	
?>
